$(function () {
    if (editType != 'info') {
        regValidate(["#_isvDataForm"]);
    }
});

function doCheckImage() {
    if(!$("#_isvDataForm").valid()) return;//校验不通过
    fileCheck("imgChoose", "logoImg", 40*1024, 64, 64,
        "您上传的图片大小超出限制范围（40k以内），无法上传，请重新上传符合要求的图片！",
        "您上传的图片尺寸不符合要求（64*64px），可能会影响APP展示效果，是否继续保存？", doIsvSave);
}

function doIsvSave() {
    var isvName = $('#isvName').val();
    var companyName = $('#companyName').val();
    var companyAddr = $('#companyAddr').val();
    var contactPerson = $('#contactPerson').val();
    var contactPhone = $('#contactPhone').val();
    var bdContact = $('#bdContact').val();
    var code = $('#code').val();
    var postData = {
        isvName : isvName,
        companyName : companyName,
        companyAddr : companyAddr,
        contactPerson : contactPerson,
        contactPhone : contactPhone,
        sortNum : 999,
        bdContact : bdContact,
        code : code
    };
    var url = basePath + 'basic/isvInfo/addIsv?t=' + new Date().getTime();
    if (editType == 'edit') {
        postData.id = oneIsvInfo.id;
        url = basePath + 'basic/isvInfo/editIsv?t=' + new Date().getTime();
    }
    showLoading();
    $.ajaxFileUpload({
        type: 'post',
        url: url,
        dataType: 'json',
        secureuri : false,
        fileElementId : ["imgChoose"],
        contentType : "application/json; charset=UTF-8",
        data: postData,
        success : function (data) {
            hideLoading();
            if (!data) {
                toastr.error(common_save_fail);
                return;
            }
            if (data.isSuccess) {
                toastr.success(common_save_success);
                doBack();
                return;
            }
            if (!data.isSuccess && data.errorCode == 'EXIST') {
                toastr.warning('【'+isvName+'】已存在');
                return;
            }
            if (!data.isSuccess) {
                toastr.error(data.errorDesc);
                return;
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
            return;
        }
    });
}

function doBack() {
    window.location.href = basePath + 'basic/isvInfo/isvPage?searchKey=' + oneIsvInfo.searchKey + '&isIsvBizExist=' + searchIsvInfo.isIsvBizExist +
        '&t=' + new Date().getTime() + '&pageNo=' + searchIsvInfo.pageNo + '&pageSize=' + searchIsvInfo.pageSize;
}

function doCheckDataChange() {
    var data = getFromData('#_isvDataForm');
    var checkData = {
        isvName : data.isvName,
        companyName : data.companyName,
        companyAddr : data.companyAddr,
        contactPerson : data.contactPerson,
        contactPhone : data.contactPhone,
        bdContact : data.bdContact,
        code : data.code,
    };
    if (editType != 'info' && (!Compare(checkData, oneIsvInfo) || $("#imgChoose").val()!= '')) {
        swalClosePageToastr(doBack);
        return;
    }
    doBack();
}